//
//  MKHomeViewController.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/7.
//  Copyright © 2017年 cc.moko. All rights reserved.
//  home页面

import UIKit

class MKHomeViewController: MKBaseViewController,UITableViewDelegate,UITableViewDataSource {

    var navigationBar:MKHomeNavigationBar!
    var listView:UITableView!
    var sectionData:Array<Array<Any>>!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.sectionData = [["最热艺人","HOTTEST STAR",true],["作品推荐","RECOMMENDED WORKS",false],["热门专题","HOT TOPICS",false],["新面孔","NEW FACE",true]]
        self.makeUI()
        
//        self.initData()
    }
    
//    func initData() -> Void {
//        MKNetWorkTool.getRequest(url: "/certificate/bizStatus", params: nil, success: {response in
//            
//            
//        }) { response in
//            
//            
//            
//        }
//    }
    
    func makeUI() -> Void {
        self.navigationBar = MKHomeNavigationBar.init(frame: CGRect.init(x: 0, y: 0, width: ScreenWidth, height: 64))
        self.view.addSubview(self.navigationBar)
        
        self.listView = UITableView.init(frame: CGRect.init(x: 0, y: 64, width: ScreenWidth, height: ScreenHeight - 64), style: .grouped)
        self.listView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0)
        self.listView.separatorStyle = .none
        self.listView.delegate = self as UITableViewDelegate
        self.listView.dataSource = self as UITableViewDataSource
        self.listView .register(MKNewFaceCell.classForCoder(), forCellReuseIdentifier: "MKNewFaceCell")
        self.listView .register(MKHotActorCell.classForCoder(), forCellReuseIdentifier: "MKHotActorCell")
        self.listView .register(MKTenEntranceCell.classForCoder(), forCellReuseIdentifier: "MKTenEntranceCell")
        self.listView .register(MKHotThemeCell.classForCoder(), forCellReuseIdentifier: "MKHotThemeCell")
        self.listView .register(MKWorkRecommendCell.classForCoder(), forCellReuseIdentifier: "MKWorkRecommendCell")
        self.view.addSubview(self.listView)
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 5
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//        if(section == 0){
//            return 2
//        }
        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if(indexPath.section == 0){
            let cell = tableView.dequeueReusableCell(withIdentifier: "MKTenEntranceCell", for: indexPath)
            return cell
        }else if(indexPath.section == 1){
            let cell = tableView.dequeueReusableCell(withIdentifier: "MKHotActorCell", for: indexPath)
            return cell
        }else if(indexPath.section == 2){
            let cell = tableView.dequeueReusableCell(withIdentifier: "MKWorkRecommendCell", for: indexPath)
            return cell
        }else if(indexPath.section == 3){
            let cell = tableView.dequeueReusableCell(withIdentifier: "MKHotThemeCell", for: indexPath)
            return cell
        }
        let cell = tableView.dequeueReusableCell(withIdentifier: "MKNewFaceCell", for: indexPath)
        return cell
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if(section == 0){
            return 0.1
        }
        return 58
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        if(section == 0){
            return nil
        }
        let sectionHeader:MKHomeSectionHeader = MKHomeSectionHeader.init(frame: CGRect.init(x: 0, y: 0, width: ScreenWidth, height: 58))
        if(section == 1){
            sectionHeader.config(title: self.sectionData[0][0] as! String, subTitle: self.sectionData[0][1] as! String, moreHiden: self.sectionData[0][2] as! Bool)
        }else if(section == 2){
            sectionHeader.config(title: self.sectionData[1][0] as! String, subTitle: self.sectionData[1][1] as! String, moreHiden: self.sectionData[1][2] as! Bool)
        }else if(section == 3){
            sectionHeader.config(title: self.sectionData[2][0] as! String, subTitle: self.sectionData[2][1] as! String, moreHiden: self.sectionData[2][2] as! Bool)
        }else if(section == 4){
            sectionHeader.config(title: self.sectionData[3][0] as! String, subTitle: self.sectionData[3][1] as! String, moreHiden: self.sectionData[3][2] as! Bool)
        }
        return sectionHeader
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 8
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if(indexPath.section == 0){
            return 165
        }else if(indexPath.section == 1){
            return 215
        }else if(indexPath.section == 2){
            return (ScreenWidth - 10) * 260 / 244 + 26
        }else if(indexPath.section == 3){
            //热门专题是3 - 6个
            return (ScreenWidth - 10) / 3 * 260 / 244 * 2 + 5 + 16
        }else{
            return 130;
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}
